<div align="left"><b><?=translate('title');?></b><br><br></div>
<?
#include('../rp2/global_functions.php');

include('wallet_db.html');

$payments_between=translate('payments_between');
$and=translate('and');
$search=translate('search');
$no_data=translate('no_data');
$data=translate('data');
$suma=translate('suma');
$valuta=translate('valuta');
$trans_no=translate('trans_no');
$paytype=translate('paytype');
$status=translate('status');
$comm=translate('comm');

$reseller_id=$id;
if (empty($f_date)) {
        #$f_date=date("Y-m-d");
	$f_date=date('Y-m-d', strtotime("-1 month"));
        $t_date=date("Y-m-d");
} else {
        $f_date=$f_date;
        $t_date=$t_date;
}
echo "<script src='calendar.js'></script>";
$params[sid] = $sid;
$params[action] = "walletPaymentHistory";
$url = "$baseURL/$webDIR/?".encode_params($params);

echo "<table width='100%' border=0 cellpadding='0' cellspacing='0' align=center>
<form action=\"$url\" method=POST>
<tr>
        <td align=center>";
	echo "<select name=by_type>
                <option value=1 "; if (empty($_POST[by_type]) or $_POST[by_type]==1) echo "selected"; echo">Refills</option>
                <option value=2 "; if ($_POST[by_type]==2) echo "selected"; echo">Withdraws</option>
                <option value=4 "; if ($_POST[by_type]==4) echo "selected"; echo">All Activity</option>
        </select>&nbsp;";
        echo "$payments_between&nbsp;<input type=text name=f_date id=f_date value=\"$f_date\" size=9 maxlength=10>
                &nbsp;<a href='#'><img src='images/calendar.gif' border=0 align='middle' onclick=\" popUpCalendar(daForm,document.getElementById('f_date'),document.getElementById('f_date'),'yyyy-mm-dd');\"></a>&nbsp;
        $and&nbsp;
        <input type=text name=t_date id=t_date value=\"$t_date\" size=9 maxlength=10>
                &nbsp;<a href='#'><img src='images/calendar.gif' border=0 align='middle' onclick=\" popUpCalendar(daForm,document.getElementById('t_date'),document.getElementById('t_date'),'yyyy-mm-dd');\"></a>&nbsp;
        &nbsp;";
echo "<input type=submit name=submit value=$search>
        <input type=hidden name=reseller_id value='$reseller_id'>
        <input type=hidden name=r value='$r'>
        </td>
</tr>
</form>
</table>";
if ($f_date!=$t_date) {
        $where .= "AND order_date >= '$f_date' AND order_date <= '$t_date'";
} else {
        $where .= "AND order_date = '$t_date'";
}
$by_type=!empty($_POST[by_type])?$_POST[by_type]:1;
switch ($by_type) {
	case '2':
		$where .= " AND status='withdraw' ";
		break;
	case '4':
		$where .= "";
		break;
	default:
		$where .= " AND status!='withdraw' ";
}
//------------------------------------------------------
$sql['type']='SELECT';
$sql['params']='*';
$sql['table']='wallet_history';
$sql['where']="reseller_id='$reseller_id' ".$where;
$sql['options']='ORDER BY id DESC';
$sql['return']='struct';
//------------------------------------------------------
if (!$result=sql_exec($sql,$dbh81,'assoc')){
//        echo "<h4><font color=red>$no_data</font></h4>";
					$errorMsg = translate('no_data');
	  			echo "<br><br>";
					include_once('errorMsg.html');
} else {
        echo "<br><br><table class='bTable' cellspacing=0>
                <tr>
                        <th>$data</th>
                        <th>$suma</th>
                        <th>$valuta</th>
                        <th>$trans_no</th>
                        <th>$paytype</th>
                        <th>$status</th>
                        <th>$comm</th>
                </tr>";
        foreach ($result as $value) {
                $order_date=$value[order_date];
                switch ($value[status]) {
                        case 'returned':
                                $ch='bgcolor=red';
                                break;
                        default:
                                $ch='';
                }
		$value[amount]=empty($value[amount])?'&nbsp;':"$value[amount]";
		$value[currency]=empty($value[currency])?'&nbsp;':"$value[currency]";
		$value[transaction_no]=empty($value[transaction_no])?'&nbsp;':"$value[transaction_no]";
		$value[paytype]=empty($value[paytype])?'&nbsp;':"$value[paytype]";
		$value[status]=empty($value[status])?'&nbsp;':"$value[status]";
		$value[return_comment]=empty($value[return_comment])?'&nbsp;':"$value[return_comment]";
                echo "<tr $ch>
                        <td align=center>$order_date</td>
                        <td align=center>"; echo sprintf("%01.2f",$value[amount]); echo"</td>
                        <td align=center>$value[currency]</td>
                        <td align=center>$value[transaction_no]</td>
                        <td align=center>$value[paytype]</td>
                        <td align=center>$value[status]</td>
                        <td align=center>$value[return_comment]</td>
                </tr>";
        }
        echo "</table>";
}
?>
